<?php

namespace App\Http\Controllers\Admin\System;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Company;
use App\Http\Controllers\Admin\System\Api\systemApi;
use App\Http\Controllers\Common\CommonApi;
use Illuminate\Support\Facades\Redis;

class systemController extends Controller
{
    public function base()
    {
        $mod = new systemApi();

        $res = $mod->list();

        return view('Admin/System/base', ['list'=>$res]);
    }

    public function save(Request $request)
    {
        //判断用户是否上传了照片
        if (!$request->toArray()['uploadfile-2'] == '') {

            $qny = new CommonApi();

            $res = $qny->uploadToQiNiu($request);
            
            if ($res['msg'] !== '上传成功') {
                return $res['msg'];
            }

            $_POST['logo_path'] = 'http://owv3oi69q.bkt.clouddn.com/'.$res['data']['key'];
        }

        $mod = new systemApi();

        $mod->chg($_POST);

        $res = $mod->list();

        Redis::del('company');

        return redirect()->action('Admin\System\systemController@base');
    }
}
